cssjshtml vue.js 路由独享守卫,组件守卫

葫芦的运维日志

下一篇 搜索 上一篇

浏览量 3904

2019/01/10 09:33


main.js路由独享守卫:

    path: '/menu', name: "menulink", component: Menu, beforeEnter: (to, from, next) => {
      alert("非登录状态不能进入此页面!");
      next('/login');
    }

main.js后置钩子:

//后置钩子
// router.afterEach((to, from) => {
//   alert('after each ')
// })

组件守卫Admin.vue:

<template>
      <h1>{{name }}</h1>

</template>

<script>
    export default {
      data(){
        return{
          name:"brownwang"
        }
      },
      beforeRouteEnter:((to, from, next) =>{
        // alert("hello "+this.name);
        // next();
        next((vm => {
          alert("hello "+vm.name);
        }))
      }),
      beforeRouteLeave:((to, from, next) => {
        if(confirm("确定离开?")==true){
          next()
        }else{
          next(false)
        }
      })
    }
</script>

<style scoped>

</style>

葫芦的运维日志

打赏

上一篇 搜索 下一篇
© 冰糖葫芦甜(bthlt.com) 2021 王梓打赏联系方式 陕ICP备17005322号-1